package sort;

public class Test {
    public static void main(String[] args) {
        int []arr={1,3,5,6,7,8,1,3,4,5,6,56,43,5634,654,543,543,563456,765,7856,65543,345,3};
        long s=System.currentTimeMillis();
        A.quickSort(arr,0,arr.length-1);
        long e=System.currentTimeMillis();
        for(int data:arr){
            System.out.println(data);
        }
        System.out.printf("所花时间:%d",(e-s));
    }
}

class A{
    public static void quickSort(int[]arr,int left,int right){
        if (left>=right){
            return;
        }
        int piv=pivition(arr,left,right);
        quickSort(arr,left,piv-1);
        quickSort(arr,piv+1,right);
    }
    public static int pivition(int[]arr,int start,int end){
        int pivot=arr[start];
        int i=start;
        while(start<end){
            while(start<end&&arr[end]>=pivot){
                end--;
            }
            while(start<end&&arr[start]<=pivot){
                start++;
            }
            swap(arr,end,start);
        }
        swap(arr,start,i);
        return start;
    }
    public static void swap(int[]arr,int i,int j){
        int tem=arr[i];
        arr[i]=arr[j];
        arr[j]=tem;
    }
}
